"""启动脚本"""
import os
import sys

def setup_environment():
    """设置运行环境"""
    # 获取程序所在目录
    if getattr(sys, 'frozen', False):
        # 打包后的路径
        application_path = os.path.dirname(sys.executable)
    else:
        # 开发环境路径
        application_path = os.path.dirname(os.path.abspath(__file__))
    
    # 设置工作目录
    os.chdir(application_path)
    
    # 确保配置文件存在
    if not os.path.exists('config.py'):
        with open('config.py', 'w', encoding='utf-8') as f:
            f.write('config = {\n    "api_key": "",\n    "system_prompt": "",\n    "listen_list": [],\n    "merge_wait_time": 2.0\n}')

if __name__ == "__main__":
    setup_environment()
    from chatai.main import main
    main() 